package com.app.couponsharelife.utils

import com.app.couponsharelife.R
import com.app.couponsharelife.data.bean.*
import com.app.couponsharelife.manage.Contacts
import com.app.couponsharelife.manage.Contacts.JD_IMAG_URL_N1
import java.math.BigDecimal
import java.text.DecimalFormat
import java.text.SimpleDateFormat
import java.util.*

/**
 *Created by xct on 2019/1/15
 *Description:
 */
class DataUtils {
    fun getCommissionRatio():String{
        //val df = DecimalFormat("#0.000")
        val commissionRatio=AppUtils.getString(Contacts.COMMISSION_RATIO,"")
        if (commissionRatio.isNotEmpty()){
            //Log.e("eeeee","------->佣金比例：${commissionRatio.toDouble()}")
            return commissionRatio
        }else{
            return "0.356"
        }
    }
    fun taobaoData(it: RemoteResultBean<HomeChiocenGoodsBean>):RemoteResultBean<HomeChiocenGoodsBean>{
        val commissionRatio=getCommissionRatio()
        if (it.data != null && it.data!!.records!!.isNotEmpty()) {
            val df = DecimalFormat("#0.00")
            it.data!!.recordss= arrayListOf()
            for (item in it.data!!.records!!) {
                val good = TaobaoGoodBean()
                good.title = item!!.title?:""
                good.coupon_info = item.couponInfo?:""
                good.zk_final_price = item.zkFinalPrice?:"0"
                good.reserve_price = item.reservePrice?:"0"
                good.num_iid = item.numIid.toString()
                good.item_id=item.numIid.toString()
                good.commission_rate = item.tkRate?:"0"
                val itemUrl=item.clickUrl?:""
                good.url = if (itemUrl.isNotEmpty()){
                    itemUrl
                }else{
                    item.itemUrl?:""
                }
                good.coupon_remain_count = item.couponRemainCount?:"0"
                good.item_url = item.itemUrl?:""
                good.pict_url = item.pictUrl?:""
                good.small_images = item.smallImages
                if (item.couponClickUrl!=null){
                   if (!item.couponClickUrl!!.startsWith("http")) {
                       good.coupon_share_url="https:${item.couponClickUrl}"
                       good.coupon_share_url_new = "https:${item.couponClickUrl}"
                   }else{
                       good.coupon_share_url=item.couponClickUrl!!
                       good.coupon_share_url_new =item.couponClickUrl!!
                   }
                }
                if (item.couponStartTime!=null&&item.couponStartTime!!.isNotEmpty()){
                    good.coupon_start_time=if (item.couponStartTime!!.contains("-")){
                        item.couponStartTime!!.replace("-",".")
                    }else{
                        item.couponStartTime!!
                    }
                }
                if (item.couponEndTime!=null&&item.couponEndTime!!.isNotEmpty()){
                    good.coupon_end_time=if (item.couponEndTime!!.contains("-")){
                        item.couponEndTime!!.replace("-",".")
                    }else{
                        item.couponEndTime!!
                    }
                }
                when(item.userType){
                    0->{
                        good.userType= R.drawable.goods_tb
                        good.goodsSource="淘宝"
                    }
                    1->{
                        good.userType= R.drawable.goods_tm
                        good.goodsSource="天猫"
                    }
                }
                good.volume =if (item.volume!=null){
                    if (item.volume!!>10000) {
                        "月销" + df.format((item.volume!!.toDouble()) / 10000) + "万"
                    }else{
                        "月销"+item.volume!!
                    }
                }else{
                    "月销0"
                }
                good.collectId = ""
                good.shop_title = item.nick?:""
                if (good.coupon_info.isNotEmpty()) {
                    good.has_coupon = true
                    val start = good.coupon_info.indexOf("减")
                    val str = good.coupon_info.substring(start + 1)
                    val end = str.indexOf("元")
                    good.coupon_price = str.substring(0, end)//str.substring(0, end).toInt().toString()
                    val couponFinalPrice = BigDecimal(good.zk_final_price).subtract(BigDecimal(good.coupon_price)).setScale(2, BigDecimal.ROUND_HALF_UP)
                    good.final_price = if (couponFinalPrice > BigDecimal.ZERO) couponFinalPrice.toString() else "0"
                    good.original_price = good.zk_final_price
                } else {
                    good.final_price = good.zk_final_price
                    good.original_price = good.reserve_price
                }
                val commission = BigDecimal(good.final_price)
                        .multiply(BigDecimal(good.commission_rate))
                        .multiply(Contacts.RETURN_RATIO.toBigDecimal())
                        .divide(BigDecimal(100))

                val vipBuyCommission = commission
                        .multiply(commissionRatio.toBigDecimal())

                val vipShareCommission = commission
                        .multiply(commissionRatio.toBigDecimal())

                val svipBuyCommission = commission
                        .multiply(commissionRatio.toBigDecimal())

                val svipShareCommission = commission
                        .multiply(commissionRatio.toBigDecimal())

                good.vip_commission = vipBuyCommission
                        .setScale(2, BigDecimal.ROUND_DOWN)
                        .toString()

                good.svip_commission = svipBuyCommission
                        .setScale(2, BigDecimal.ROUND_DOWN)
                        .toString()
                if (good.small_images != null &&
                        good.small_images!!.toString() != "" &&
                        good.small_images!!.toString() != "[]") {
                    var array = good.small_images!!.toString()
                    array=array.replace("{string=","").replace("}","")
                    //array=array.substring(0,array.length)
                    if (!array.contains(",")) {
                        good.images.add(array.trim())
                    } else {
                        val imagess = array.substring(1, array.length - 1).split(",")
                        for (i in 0 until imagess.size){
                            val image=imagess[i].trim()
                            if (image.startsWith("http")){
                                good.images.add(image)
                            }else{
                                good.images.add("https:$image")
                            }
                        }
                    }
                }
                it.data!!.recordss.add(good)
            }}else{
            it.data!!.recordss= arrayListOf()
        }
        return it
    }
    fun taobaoSearchData(it: RemoteResultBean<SearchTBGoodsListBean>):RemoteResultBean<SearchTBGoodsListBean>{
        val commissionRatio=getCommissionRatio()
        if (it.data != null && it.data!!.records!!.isNotEmpty()) {
            val df = DecimalFormat("#0.00")
            it.data!!.recordss= arrayListOf()
            for (item in it.data!!.records!!) {
                val good = TaobaoGoodBean()
                good.title = item!!.title?:""
                good.coupon_info = item.couponInfo?:""
                good.zk_final_price = item.zkFinalPrice?:""
                good.reserve_price = item.reservePrice?:""
                good.num_iid = item.numIid.toString()
                good.item_id=item.numIid.toString()
                val commission_rate=item.commissionRate?:"0"
                good.commission_rate =commission_rate
                if (item.url!=null&&item.url.isNotEmpty()){
                    if (item.url.startsWith("http")){
                        good.url = item.url
                    }else{
                        good.url = "https:${item.url}"
                    }
                }
                good.coupon_remain_count = (item.couponRemainCount?:0).toString()
                good.item_url = item.itemUrl?:""
                good.pict_url = item.pictUrl?:""
                good.small_images = item.smallImages
                if (item.couponShareUrl!=null){
                    if (!item.couponShareUrl!!.startsWith("http")) {
                        good.coupon_share_url="https:${item.couponShareUrl}"
                        good.coupon_share_url_new = "https:${item.couponShareUrl}"
                    }else{
                        good.coupon_share_url=item.couponShareUrl!!
                        good.coupon_share_url_new =item.couponShareUrl!!
                    }
                }
                if (item.couponStartTime!=null&&item.couponStartTime!!.isNotEmpty()){
                    good.coupon_start_time=if (item.couponStartTime!!.contains("-")){
                        item.couponStartTime!!.replace("-",".")
                    }else{
                        item.couponStartTime!!
                    }
                }
                if (item.couponEndTime!=null&&item.couponEndTime!!.isNotEmpty()){
                    good.coupon_end_time=if (item.couponEndTime!!.contains("-")){
                        item.couponEndTime!!.replace("-",".")
                    }else{
                        item.couponEndTime!!
                    }
                }
                when(item.userType){
                    0->{
                        good.userType= R.drawable.goods_tb
                        good.goodsSource="淘宝"
                    }
                    1->{
                        good.userType= R.drawable.goods_tm
                        good.goodsSource="天猫"
                    }
                }
                good.volume =if (item.volume!!>10000){
                    "月销"+df.format((item.volume!!.toDouble())/10000)+"万"
                }else{
                    "月销"+item.volume!!
                }
                good.collectId = ""
                good.shop_title = item.shopTitle?:""

                if (good.coupon_info.isNotEmpty()) {
                    good.has_coupon = true
                    val start = good.coupon_info.indexOf("减")
                    val str = good.coupon_info.substring(start + 1)
                    val end = str.indexOf("元")
                    good.coupon_price = str.substring(0, end)//str.substring(0, end).toInt().toString()
                    val couponFinalPrice = BigDecimal(good.zk_final_price).subtract(BigDecimal(good.coupon_price)).setScale(2, BigDecimal.ROUND_HALF_UP)
                    good.final_price = if (couponFinalPrice > BigDecimal.ZERO) couponFinalPrice.toString() else "0"
                    good.original_price = good.zk_final_price
                } else {
                    good.final_price = good.zk_final_price
                    good.original_price = good.reserve_price
                }
                val commission = BigDecimal(good.final_price)
                        .multiply(BigDecimal(good.commission_rate))
                        .multiply(Contacts.RETURN_RATIO.toBigDecimal())
                        .divide(BigDecimal(10000))

                val vipBuyCommission = commission
                        .multiply(commissionRatio.toBigDecimal())

                val vipShareCommission = commission
                        .multiply(commissionRatio.toBigDecimal())

                val svipBuyCommission = commission
                        .multiply(commissionRatio.toBigDecimal())

                val svipShareCommission = commission
                        .multiply(commissionRatio.toBigDecimal())

                good.vip_commission = vipBuyCommission
                        .setScale(2, BigDecimal.ROUND_DOWN)
                        .toString()

                good.svip_commission = svipBuyCommission
                        .setScale(2, BigDecimal.ROUND_DOWN)
                        .toString()
                if (good.small_images != null &&
                        good.small_images!!.toString() != "" &&
                        good.small_images!!.toString() != "[]") {
                    var array = good.small_images!!.toString()
                    array=array.replace("{string=","").replace("}","")
                    //array=array.substring(0,array.length)
                    if (!array.contains(",")) {
                        good.images.add(array.trim())
                    } else {
                        val imagess = array.substring(1, array.length - 1).split(",")
                        for (i in 0 until imagess.size){
                            val image=imagess[i].trim()
                            if (image.startsWith("http")){
                                good.images.add(image)
                            }else{
                                good.images.add("https:$image")
                            }
                        }
                    }
                }
                it.data!!.recordss.add(good)
            }}else{
            it.data!!.recordss= arrayListOf()
        }
        return it
    }
    fun pddData(it: RemoteResultBean<PDDGoodsListBean>):RemoteResultBean<PDDGoodsListBean>{
        val commissionRatio=getCommissionRatio()
        val simpleDateFormat = SimpleDateFormat("yyyy.MM.dd", Locale.getDefault())
        //Log.e("eeee","----->"+it.toString())
        if (it.data != null && it.data!!.records!=null&&it.data!!.records!!.isNotEmpty()) {
            //Log.e("eeee","----->不是空的")
            val df = DecimalFormat("#0.00")
            val df1 =DecimalFormat("#0")
            it.data!!.recordss= arrayListOf()
            for (item in it.data!!.records!!) {
                val good = TaobaoGoodBean()
                good.title = item!!.goods_name?:""
                val couponDiscount=(item.coupon_discount?:0).toDouble()
                good.coupon_price =df1.format(couponDiscount/100)
                val normal_price=(item.min_normal_price?:0).toDouble()
                val zkprice=normal_price-couponDiscount
                good.zk_final_price = df.format(normal_price/100)
                good.final_price=df.format(zkprice/100)
                good.reserve_price = df.format(normal_price/100)
                good.original_price=df.format(normal_price/100)
                good.num_iid = (item.goods_id?:0).toString()
                val commission_rate=item.promotion_rate?:0
                good.commission_rate = commission_rate.toString()
                good.url =""
                good.coupon_remain_count = (item.coupon_remain_quantity?:0).toString()
                good.item_url =""
                good.pict_url = item.goods_thumbnail_url?:item.goods_image_url!!
                if (item.goods_gallery_urls!=null&& item.goods_gallery_urls!!.isNotEmpty()){
                    good.images.addAll(item.goods_gallery_urls!!)
                }
                good.coupon_share_url=""
                good.coupon_share_url_new = ""
                if (item.coupon_start_time!=null&&item.coupon_start_time!!>0){
                    good.coupon_start_time=simpleDateFormat.format(item.coupon_start_time!!*1000)
                }else{
                    good.coupon_start_time=""
                }
                if (item.coupon_end_time!=null&&item.coupon_end_time!!>0){
                    good.coupon_end_time=simpleDateFormat.format(item.coupon_end_time!!*1000)
                }else{
                    good.coupon_end_time=""
                }
                good.userType= R.drawable.goods_pdd
                good.goodsSource="拼多多"
                good.volume =if (item.sold_quantity!!>10000){
                    "月销"+df.format((item.sold_quantity!!.toDouble())/10000)+"万"
                }else{
                    "月销"+item.sold_quantity!!
                }
                good.collectId = ""
                good.shop_title = item.mall_name?:""
                good.has_coupon=item.has_coupon!!
                val commission = BigDecimal(good.final_price)
                        .multiply(BigDecimal(good.commission_rate))
                        .multiply(Contacts.RETURN_RATIO.toBigDecimal())
                        .divide(BigDecimal(1000))

                val vipBuyCommission = commission
                        .multiply(commissionRatio.toBigDecimal())

                val vipShareCommission = commission
                        .multiply(commissionRatio.toBigDecimal())

                val svipBuyCommission = commission
                        .multiply(commissionRatio.toBigDecimal())

                val svipShareCommission = commission
                        .multiply(commissionRatio.toBigDecimal())

                good.vip_commission = vipBuyCommission
                        .setScale(2, BigDecimal.ROUND_DOWN)
                        .toString()

                good.svip_commission = svipBuyCommission
                        .setScale(2, BigDecimal.ROUND_DOWN)
                        .toString()
                it.data!!.recordss!!.add(good)
            }}else{
            it.data!!.recordss= arrayListOf()
        }
        return it
    }
    fun jdData(it: RemoteResultBean<JDGoodsListBean>):RemoteResultBean<JDGoodsListBean>{
        val commissionRatio=getCommissionRatio()
        val simpleDateFormat = SimpleDateFormat("yyyy.MM.dd", Locale.getDefault())
        if (it.data != null && it.data!!.records!!.isNotEmpty()) {
            val df = DecimalFormat("#0.00")
            val df1 =DecimalFormat("#0")
            it.data!!.recordss= arrayListOf()
            for (item in it.data!!.records!!) {
                val good = TaobaoGoodBean()
                good.title = item.skuName?:""
                val couponList=item.couponList
                var coupon="0"
                var couponDiscount=0.0
                if (couponList!=null&& couponList.isNotEmpty()){
                    good.has_coupon=true
                    coupon=df1.format((couponList[0].discount?:"0").toDouble())
                    couponDiscount=coupon.toDouble()
                    good.url ="https:"+couponList[0].link!!
                    if (couponList[0].beginTime!=null){
                        val date=Date(couponList[0].beginTime!!.toLong())
                        //Log.e("eeee","--->${couponList[0].beginTime}")
                        try {
                            good.coupon_start_time=simpleDateFormat.format(date)
                        }catch (e:Exception){
                            good.coupon_start_time=""
                        }
                    }else{
                        good.coupon_start_time=""
                    }
                    if (couponList[0].endTime!=null&&couponList[0].endTime!!.isNotEmpty()){
                        val date=Date(couponList[0].endTime!!.toLong())
                        //Log.e("eeee","--->${couponList[0].endTime}")
                        try {
                            good.coupon_end_time=simpleDateFormat.format(date)
                        }catch (e:Exception){
                            good.coupon_end_time=""
                        }
                    }else{
                        good.coupon_end_time=""
                    }
                }else{
                    good.has_coupon=false
                }
                good.coupon_price =coupon
                val goodsprice=item.wlPrice?:"0"
                val normal_price=goodsprice.toDouble()
                val zkprice=normal_price-couponDiscount
                good.final_price =if (zkprice>0){
                    //good.has_coupon=true
                    df.format(zkprice)
                }else{
                    good.has_coupon=false
                    df.format(normal_price)
                }
                good.zk_final_price=item.wlPrice?:"0"
                good.reserve_price = item.wlPrice!!
                good.original_price=df.format(normal_price)
                good.num_iid = (item.skuId?:0).toString()
                val commissions=item.wlCommissionShare?:"0"
                good.commission_rate = commissions
                good.coupon_remain_count ="0"
                good.item_url =""
                good.pict_url = JD_IMAG_URL_N1+item.imageurl
                good.images.add(JD_IMAG_URL_N1+item.imageurl)
                good.coupon_share_url=""
                good.coupon_share_url_new = "simpleDateFormat"
                good.userType= R.drawable.goods_jd
                good.goodsSource="京东"
                /*good.volume =if (item.in!!>10000){
                    "月销"+df.format(item.sold_quantity!!/10000)+"万"
                }else{
                    "月销"+item.sold_quantity!!
                }*/
                good.volume="月销"+item.inOrderCount!!
                good.collectId = ""
                good.shop_title = ""
                val commission = BigDecimal(good.final_price)
                        .multiply(BigDecimal(good.commission_rate))
                        .multiply(Contacts.RETURN_RATIO.toBigDecimal())
                        .divide(BigDecimal(100))

                val vipBuyCommission = commission
                        .multiply(commissionRatio.toBigDecimal())

                val vipShareCommission = commission
                        .multiply(commissionRatio.toBigDecimal())

                val svipBuyCommission = commission
                        .multiply(commissionRatio.toBigDecimal())

                val svipShareCommission = commission
                        .multiply(commissionRatio.toBigDecimal())

                good.vip_commission = vipBuyCommission
                        .setScale(2, BigDecimal.ROUND_DOWN)
                        .toString()

                good.svip_commission = svipBuyCommission
                        .setScale(2, BigDecimal.ROUND_DOWN)
                        .toString()
                it.data!!.recordss!!.add(good)
            }}else{
            it.data!!.recordss= arrayListOf()
        }
        return it
    }
    fun hdkData(it: RemoteResultBean<HDKGoodsBean>):RemoteResultBean<HDKGoodsBean>{
        val commissionRatio=getCommissionRatio()
        val simpleDateFormat = SimpleDateFormat("yyyy.MM.dd", Locale.getDefault())
        if (it.data != null && it.data!!.data!!.isNotEmpty()) {
            //Log.e("eeee","---->集合不为空")
            val df = DecimalFormat("#0.00")
            it.data!!.datas= arrayListOf()
            for (item in it.data!!.data!!) {
                val good = TaobaoGoodBean()
                good.title = item!!.itemtitle?:""
                good.coupon_info = item.couponexplain?:""
                good.zk_final_price = item.itemendprice?:"0.00"
                good.reserve_price = item.itemprice?:"0.00"
                good.num_iid = item.itemid?:""
                good.item_id=item.itemid?:""
                val commission_rate=item.tkrates?:"0"
                good.commission_rate = commission_rate
                good.todaysale=item.todaysale?:"0"
                good.coupon_remain_count = item.couponsurplus?:"0"
                good.pict_url = item.itempic?:""+"_310x310.jpg"
                good.goodsWenAn=item.itemdesc?:""
                //good.small_images = item.smallImages
                good.images.add(good.pict_url.toString())
                good.images.add("http://img.haodanku.com/${item.itempic_copy}")
                if (item.couponurl!=null){
                    if (!item.couponurl!!.startsWith("http")) {
                        good.coupon_share_url="https:${item.couponurl}"
                        good.coupon_share_url_new = "https:${item.couponurl}"
                    }else{
                        good.coupon_share_url=item.couponurl!!
                        good.coupon_share_url_new =item.couponurl!!
                    }
                }
                good.url = good.coupon_share_url
                good.item_url = good.coupon_share_url
                if (item.couponstarttime!=null&&item.couponstarttime!!.isNotEmpty()){
                    good.coupon_start_time=if (item.couponstarttime!!.contains("-")){
                        item.couponstarttime!!.replace("-",".")
                    }else{
                        item.couponstarttime!!
                    }
                    if(!good.coupon_start_time.contains(".")){
                        if (good.coupon_start_time.length>10){
                            good.coupon_start_time=simpleDateFormat.format(good.coupon_start_time.toLong())
                        }else{
                            good.coupon_start_time=simpleDateFormat.format(good.coupon_start_time.toLong()*1000)
                        }
                    }
                }
                if (item.couponendtime!=null&&item.couponendtime!!.isNotEmpty()){
                    good.coupon_end_time=if (item.couponendtime!!.contains("-")){
                        item.couponendtime!!.replace("-",".")
                    }else{
                        item.couponendtime!!
                    }
                    if(!good.coupon_end_time.contains(".")){
                        if (good.coupon_end_time.length>10){
                            good.coupon_end_time=simpleDateFormat.format(good.coupon_end_time.toLong())
                        }else{
                            good.coupon_end_time=simpleDateFormat.format(good.coupon_end_time.toLong()*1000)
                        }
                    }
                }
                when(item.shoptype){
                    "C"->{
                        good.userType= R.drawable.goods_tb
                        good.goodsSource="淘宝"
                    }
                    "B"->{
                        good.userType= R.drawable.goods_tm
                        good.goodsSource="天猫"
                    }
                }
                good.goodsSource1="好单库"
                val goodsXLNumber=(item.itemsale?:"0").toDouble()
                good.volume =if (goodsXLNumber>10000){
                    "月销"+df.format(goodsXLNumber/10000)+"万"
                }else{
                    "月销${goodsXLNumber.toInt()}"
                }
                good.collectId = ""
                good.shop_title = item.shopname?:""
                /*if (good.coupon_info.isNotEmpty()) {
                    good.has_coupon = true
                    val start = good.coupon_info.indexOf("减")
                    val str = good.coupon_info.substring(start + 1)
                    val end = str.indexOf("元")
                    good.coupon_price = str.substring(0, end)
                    val couponFinalPrice = BigDecimal(good.zk_final_price).subtract(BigDecimal(good.coupon_price)).setScale(2, BigDecimal.ROUND_HALF_UP)
                    good.final_price = if (couponFinalPrice > BigDecimal.ZERO) couponFinalPrice.toString() else "0"
                    good.original_price = good.zk_final_price
                } else {
                    good.final_price = good.zk_final_price
                    good.original_price = good.reserve_price
                }*/
                if (item.couponmoney!=null&&item.couponmoney!!.isNotEmpty()){
                    good.has_coupon = true
                    good.coupon_price =item.couponmoney!!
                    good.final_price =item.itemendprice?:"0.00"
                    good.original_price = item.itemprice?:"0.00"
                }else{
                    good.coupon_price ="0"
                    good.final_price =item.itemendprice?:"0.00"
                    good.original_price = item.itemprice?:"0.00"
                }
                val commission = BigDecimal(good.final_price)
                        .multiply(BigDecimal(good.commission_rate))
                        .multiply(Contacts.RETURN_RATIO.toBigDecimal())
                        .divide(BigDecimal(100))

                val vipBuyCommission = commission
                        .multiply(commissionRatio.toBigDecimal())

                val vipShareCommission = commission
                        .multiply(commissionRatio.toBigDecimal())

                val svipBuyCommission = commission
                        .multiply(commissionRatio.toBigDecimal())

                val svipShareCommission = commission
                        .multiply(commissionRatio.toBigDecimal())

                good.vip_commission = vipBuyCommission
                        .setScale(2, BigDecimal.ROUND_DOWN)
                        .toString()

                good.svip_commission = svipBuyCommission
                        .setScale(2, BigDecimal.ROUND_DOWN)
                        .toString()
                /*if (good.small_images != null &&
                        good.small_images!!.toString() != "" &&
                        good.small_images!!.toString() != "[]") {
                    var array = good.small_images!!.toString()
                    array=array.replace("{string=","").replace("}","")
                    //array=array.substring(0,array.length)
                    if (!array.contains(",")) {
                        good.images.add(array.trim())
                    } else {
                        val imagess = array.substring(1, array.length - 1).split(",")
                        for (i in 0 until imagess.size){
                            val image=imagess[i].trim()
                            if (image.startsWith("http")){
                                good.images.add(image)
                            }else{
                                good.images.add("https:$image")
                            }
                        }
                    }
                }*/
                it.data!!.datas.add(good)
            }}else{
            it.data!!.datas= arrayListOf()
            //Log.e("eeee","---->集合为空")
        }
        return it
    }
    fun hdkData1(it: RemoteResultBean<BrandSpecialItemBean>):RemoteResultBean<BrandSpecialItemBean>{
        val commissionRatio=getCommissionRatio()
        val simpleDateFormat = SimpleDateFormat("yyyy.MM.dd", Locale.getDefault())
        if (it.data != null && it.data!!.singleBrandInfor!=null
                &&it.data!!.singleBrandInfor!!.data!=null&&it.data!!.singleBrandInfor!!.data!!.isNotEmpty()
                &&it.data!!.singleBrandInfor!!.data!![0]!=null&&it.data!!.singleBrandInfor!!.data!![0]!!.items!=null
        &&it.data!!.singleBrandInfor!!.data!![0]!!.items!!.isNotEmpty()) {
            //Log.e("eeee","---->集合不为空")
            val df = DecimalFormat("#0.00")
            it.data!!.singleBrandInfor!!.data!![0]!!.datas= arrayListOf()
            for (item in it.data!!.singleBrandInfor!!.data!![0]!!.items!!) {
                val good = TaobaoGoodBean()
                good.title = item!!.itemtitle?:""
                good.coupon_info = item.couponexplain?:""
                good.zk_final_price = item.itemendprice?:"0.00"
                good.reserve_price = item.itemprice?:"0.00"
                good.num_iid = item.itemid?:""
                good.item_id=item.itemid?:""
                val commission_rate=item.tkrates?:"0"
                good.commission_rate = commission_rate
                good.todaysale=item.todaysale?:"0"
                //good.coupon_remain_count = item.couponsurplus?:"0"
                good.pict_url = item.itempic?:""+"_310x310.jpg"
                good.goodsWenAn=item.itemdesc?:""
                //good.small_images = item.smallImages
                good.images.add(good.pict_url.toString())
                good.images.add("http://img.haodanku.com/${item.itempic_copy}")
                if (item.couponurl!=null){
                    if (!item.couponurl!!.startsWith("http")) {
                        good.coupon_share_url="https:${item.couponurl}"
                        good.coupon_share_url_new = "https:${item.couponurl}"
                    }else{
                        good.coupon_share_url=item.couponurl!!
                        good.coupon_share_url_new =item.couponurl!!
                    }
                }
                good.url = good.coupon_share_url
                good.item_url = good.coupon_share_url
                if (item.couponstarttime!=null&&item.couponstarttime!!.isNotEmpty()){
                    good.coupon_start_time=if (item.couponstarttime!!.contains("-")){
                        item.couponstarttime!!.replace("-",".")
                    }else{
                        item.couponstarttime!!
                    }
                    if(!good.coupon_start_time.contains(".")){
                        if (good.coupon_start_time.length>10){
                            good.coupon_start_time=simpleDateFormat.format(good.coupon_start_time.toLong())
                        }else{
                            good.coupon_start_time=simpleDateFormat.format(good.coupon_start_time.toLong()*1000)
                        }
                    }
                }
                if (item.couponendtime!=null&&item.couponendtime!!.isNotEmpty()){
                    good.coupon_end_time=if (item.couponendtime!!.contains("-")){
                        item.couponendtime!!.replace("-",".")
                    }else{
                        item.couponendtime!!
                    }
                    if(!good.coupon_end_time.contains(".")){
                        if (good.coupon_end_time.length>10){
                            good.coupon_end_time=simpleDateFormat.format(good.coupon_end_time.toLong())
                        }else{
                            good.coupon_end_time=simpleDateFormat.format(good.coupon_end_time.toLong()*1000)
                        }
                    }
                }
                when(item.shoptype){
                    "C"->{
                        good.userType= R.drawable.goods_tb
                        good.goodsSource="淘宝"
                    }
                    "B"->{
                        good.userType= R.drawable.goods_tm
                        good.goodsSource="天猫"
                    }
                }
                good.goodsSource1="好单库"
                val goodsXLNumber=(item.itemsale?:"0").toDouble()
                good.volume =if (goodsXLNumber>10000){
                    "月销"+df.format(goodsXLNumber/10000)+"万"
                }else{
                    "月销${goodsXLNumber.toInt()}"
                }
                good.collectId = ""
                good.shop_title = item.shopname?:""
                /*if (good.coupon_info.isNotEmpty()) {
                    good.has_coupon = true
                    val start = good.coupon_info.indexOf("减")
                    val str = good.coupon_info.substring(start + 1)
                    val end = str.indexOf("元")
                    good.coupon_price = str.substring(0, end)
                    val couponFinalPrice = BigDecimal(good.zk_final_price).subtract(BigDecimal(good.coupon_price)).setScale(2, BigDecimal.ROUND_HALF_UP)
                    good.final_price = if (couponFinalPrice > BigDecimal.ZERO) couponFinalPrice.toString() else "0"
                    good.original_price = good.zk_final_price
                } else {
                    good.final_price = good.zk_final_price
                    good.original_price = good.reserve_price
                }*/
                if (item.couponmoney!=null&&item.couponmoney!!.isNotEmpty()){
                    good.has_coupon = true
                    good.coupon_price =item.couponmoney!!
                    good.final_price =item.itemendprice?:"0.00"
                    good.original_price = item.itemprice?:"0.00"
                }else{
                    good.coupon_price ="0"
                    good.final_price =item.itemendprice?:"0.00"
                    good.original_price = item.itemprice?:"0.00"
                }
                val commission = BigDecimal(good.final_price)
                        .multiply(BigDecimal(good.commission_rate))
                        .multiply(Contacts.RETURN_RATIO.toBigDecimal())
                        .divide(BigDecimal(100))

                val vipBuyCommission = commission
                        .multiply(commissionRatio.toBigDecimal())

                val vipShareCommission = commission
                        .multiply(commissionRatio.toBigDecimal())

                val svipBuyCommission = commission
                        .multiply(commissionRatio.toBigDecimal())

                val svipShareCommission = commission
                        .multiply(commissionRatio.toBigDecimal())

                good.vip_commission = vipBuyCommission
                        .setScale(2, BigDecimal.ROUND_DOWN)
                        .toString()

                good.svip_commission = svipBuyCommission
                        .setScale(2, BigDecimal.ROUND_DOWN)
                        .toString()
                /*if (good.small_images != null &&
                        good.small_images!!.toString() != "" &&
                        good.small_images!!.toString() != "[]") {
                    var array = good.small_images!!.toString()
                    array=array.replace("{string=","").replace("}","")
                    //array=array.substring(0,array.length)
                    if (!array.contains(",")) {
                        good.images.add(array.trim())
                    } else {
                        val imagess = array.substring(1, array.length - 1).split(",")
                        for (i in 0 until imagess.size){
                            val image=imagess[i].trim()
                            if (image.startsWith("http")){
                                good.images.add(image)
                            }else{
                                good.images.add("https:$image")
                            }
                        }
                    }
                }*/
                it.data!!.singleBrandInfor!!.data!![0]!!.datas.add(good)
            }}else{
            it.data!!.singleBrandInfor!!.data!![0]!!.items= arrayListOf()
            //Log.e("eeee","---->集合为空")
        }
        return it
    }
}